<script>
import { h, resolveComponent } from '@vue/runtime-core'
export default {
  props: {
    treeData:{
      type: Array,
      default: () => []
    }
  },
  setup(props){ 
    const child = (children, title) => {
      if ( !Array.isArray(children)){
        return
      }
      if (children) {
        children.map(node => {
          const childs = (node.children && node.children.length > 0) ? node.children : null
          return child(childs, node.name)
        })
      }
      return h(resolveComponent('van-collapse-item'), {title})
    }
    return () => {
      return h(
      resolveComponent('van-collapse',{'v-model':a}), 
      {},
        props.treeData.map(node => {
          return child(node.children,node.name)
        })
      );
    }
  }
}
</script> 